<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>笛卡尔转弧度坐标 弧度坐标转角度坐标</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      #cesiumContainer {
        width: 100vw;
        height: 100vh;
      }
      #cesiumContainer .cesium-viewer-bottom {
        /* 去除cesium logo */
        display: none;
      }
    </style>
    <link
      rel="stylesheet"
      href="../node_modules/cesium/Build/Cesium/Widgets/widgets.css"
    />
    <script src="../node_modules/cesium/Build/Cesium/Cesium.js"></script>
  </head>
  <body>
    <div id="cesiumContainer"></div>
    <script>
      console.log(`
        包依赖使用的是1.99的
        中文官网: https://www.vvpstk.com/public/Cesium/Documentation/createWorldTerrain.html
        `);
      console.log(Cesium);
      //   使用自己的密钥
      Cesium.Ion.defaultAccessToken =
        "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyY2RkZTQ4OS0wYzRlLTQyNmMtYmFjNy0zMzI3MWEwZmYwODIiLCJpZCI6MjMxODE5LCJpYXQiOjE3MjI0MTY0Mzh9.rRYOzcdNEqL45HmrFguJzNk2KCBb38afCpPyedi0bZ0";

      //   创建地图实例
      const viewer = new Cesium.Viewer("cesiumContainer", {});

      //   返回的是一个笛卡尔坐标
      const cartesian1 = Cesium.Cartesian3.fromDegrees(110, 20, 20); //经 纬 高度
      const cartesian2 = Cesium.Cartesian3.fromDegrees(110, 20, 50); //经 纬 高度
      console.log("cartesian1", cartesian1);
      console.log("cartesian2", cartesian2);

      //   笛卡尔转弧度坐标
      let cartographic = Cesium.Cartographic.fromCartesian(cartesian1);
      console.log("cartographic", cartographic);
      // 弧度坐标转角度坐标  有 0.1+0.2 小数问题
      //   let lon = (180 / Math.PI) * cartographic.longitude;
      //   let lat = (180 / Math.PI) * cartographic.latitude;
      //   console.log(lon, lat);

      // 弧度坐标转角度坐标 Cesium自带的api 精确的很
      let lon = Cesium.Math.toDegrees(cartographic.longitude);
      let lat = Cesium.Math.toDegrees(cartographic.latitude);
      console.log(lon, lat, cartographic.height);
    </script>
  </body>
</html>
